// import { Router } from 'express'
import Vue from 'vue'
import Router from 'vue-router'
import Index from '../views/index.vue'
import Register from '../views/Register.vue'
import Notfound from '../views/404.vue'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
import InfoShow from '../views/InfoShow.vue'
import FundList from '../views/FundList.vue'
const router = new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: [{
            path: '/',
            name: 'register',
            component: Register
        },
        {
            path: '/index',
            name: 'index',
            component: Index,
            children: [
                { path: '', component: Home },
                { path: '/home', name: 'home', component: Home },
                { path: '/fundlist', name: 'fundlist', component: FundList }
            ]
        },
        { path: '/infoshow', name: 'infoshow', component: InfoShow },
        // { path: '/fundlist', name: 'fundlist', component: FundList },
        {
            path: '/register',
            name: 'register',
            component: Register
        },
        {
            path: '/login',
            name: 'login',
            component: Login
        },
        {
            path: '*',
            name: '/404',
            component: Notfound
        }
    ]
})
Vue.use(Router)

router.beforeEach((to, from, next) => {
    const isLogin = localStorage.eleToken ? true : false;
    if (to.path == '/login' || to.path == '/register' || from.path == '/login' || from.path == '/index' || from.path == '/infoshow' || from.path == '/home' || from.path == '/fundlist') {
        next();
    } else {
        isLogin ? next() : next('/login');
    }
})

export default router;

// const routes = [
//   {
//     path: '/',
//     name: 'home',
//     component: HomeView
//   }
// ]

// const router = new VueRouter({
//   routes
// })

// export default router